<?PHP
	/*
		Class: Query
		Clase que genera las consultas para ejecutarlas
	*/
	class Query {
		var $motor = NULL;
		var $type = NULL;
		var $extendedtype = NULL;
		var $select = "*";
		var $extendselect = NULL;
		var $from = NULL;
		var $join = array();
		var $limit = NULL;
		var $where = NULL;
		var $group = NULL;
		var $order = NULL;
		var $batchMode = FALSE;
		var $keys = NULL;
		var $values = NULL;
		var $__processfounds__ = false;
		function Query($from=NULL,$type="select",$motor="MySQL"){
			import("persistence.database.sql.".$motor);
			if($from!=null) $this->from = $from;
			$this->type = $type;
			$this->motor = $motor;
		}
		
		function countFounds($bool=TRUE){
			$this->__processfounds__ = $bool;
		}
		
		/*
			Function: build
			Genera el cadena de texto de la consulta creada dentro del objeto
			Returns: String
			La consulta en texto.
		*/
		function build(){
			$method = "buildSelect";
			switch(strToLower($this->type)){
				case "insert":
					$method = "buildInsert";
					break;
				case "update":
					$method = "buildUpdate";
					break;
				case "delete":
					$method = "buildDelete";
					break;
				case "select":
				default:
					$method = "buildSelect";
					break;
			}
			$queryString = call_user_func(array($this->motor,$method),$this);
			return $queryString;
		}
	}
?>
